package com.mycompany.project.server;

import java.util.ArrayList;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import marketplace.componente.servicios.AdminServiciosRemote;
import marketplace.objects.PaqueteServiciosBO;
import marketplace.objects.ServicioBO;

import com.mycompany.project.client.AdminServiciosService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class AdminServiciosServiceImpl extends RemoteServiceServlet implements AdminServiciosService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void registrarServicio(ServicioBO nServicio, String tipo) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			adminS.registrarServicio(nServicio, tipo);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}  

	}

	@Override
	public ServicioBO consultarServicio(long id) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			return adminS.consultarServicio(id);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}

	@Override
	public void eliminarServicio(long id) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			adminS.eliminarServicio(id);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		
	}

	@Override
	public void editarServicio(ServicioBO nServicio, String tipo) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			adminS.editarServicio(nServicio, tipo);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		
	}

	@Override
	public ArrayList<ServicioBO> consultarServiciosPorProveedor(
			String loginProveedor) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			return adminS.consultarServiciosPorProveedor(loginProveedor);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}

	@Override
	public ArrayList<ServicioBO> consultarServiciosPorTipo(String tipo) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			return adminS.consultarServiciosPorTipo(tipo);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}

	@Override
	public ArrayList<ServicioBO> consultarServiciosPorTipoYParametro(
			String tipo, String parametro, String valorParametro) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			return adminS.consultarServiciosPorTipoYParametro(tipo, parametro, valorParametro);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}

	@Override
	public ArrayList<ServicioBO> consultarServicioPorParametro(
			String parametro, String valorParametro) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			return adminS.consultarServicioPorParametro(parametro, valorParametro);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}

	@Override
	public void registrarPaqueteServicios(PaqueteServiciosBO nPaquete) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			adminS.registrarPaqueteServicios(nPaquete);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		
	}

	@Override
	public PaqueteServiciosBO consultarPaqueteServicios(long id) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			return adminS.consultarPaqueteServicios(id);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}

	@Override
	public void editarPaqueteServicios(PaqueteServiciosBO nPaquete) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			adminS.editarPaqueteServicios(nPaquete);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		
	}

	@Override
	public ArrayList<PaqueteServiciosBO> consultarPaqueteServiciosPorProveedor(
			String loginProvedor) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			return adminS.consultarPaqueteServiciosPorProveedor(loginProvedor);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}

	@Override
	public ArrayList<PaqueteServiciosBO> consultarPaqueteServiciosPorParametro(
			String param, String valorParametro) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			AdminServiciosRemote adminS = (AdminServiciosRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteServicios/AdminServicios");
			return adminS.consultarPaqueteServiciosPorParametro(param, valorParametro);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}
}
